package view;


import model.Share;
import view.AbstractShareView;
  
/**
 *
 * @author  diego
 */
public class ShareView extends AbstractShareView {

      
    /** Creates new form ShareView
     * @param share 
     */
    public ShareView( Share share ) {
        super( share ); 
         
        initComponents();
        loadTableModel();
        updateDisplay();
    }
    
     
    public void loadTableModel(){
        jtShare.setModel(new javax.swing.table.DefaultTableModel(
            getShare().getAvaliableShares(),
            getShare().getParams()
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.Double.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jspMarketShare = new javax.swing.JScrollPane();
        jtShare = new javax.swing.JTable();

        setBackground(new java.awt.Color(251, 252, 170));
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mercado de Ativos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 1, 13), new java.awt.Color(113, 196, 243))); // NOI18N
        setPreferredSize(new java.awt.Dimension(500, 200));

        jspMarketShare.setBackground(new java.awt.Color(254, 254, 254));

        jtShare.setAutoCreateRowSorter(true);
        jtShare.setBackground(new java.awt.Color(254, 254, 254));
        jtShare.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Ativo", "Preço", "Cor", "Variação", "Periodo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jtShare.setCellSelectionEnabled(true);
        jtShare.setGridColor(new java.awt.Color(1, 1, 1));
        jtShare.setPreferredSize(new java.awt.Dimension(498, 198));
        jspMarketShare.setViewportView(jtShare);
        jtShare.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jspMarketShare, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jspMarketShare, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jspMarketShare;
    private javax.swing.JTable jtShare;
    // End of variables declaration//GEN-END:variables
    public void updateDisplay() {
       loadTableModel(); 
   }
   
}
